
{mfdeclre.i}
                                                                                          
DEFINE VARIABLE state LIKE pt_status .

DEFINE BUFFER b_pt FOR pt_mstr .

FORM 
    pt_mstr.pt_part
    pt_mstr.pt_status
    state
    WITH FRAME a STREAM-IO DOWN.
   

/*************************************************************************************************************************************/
FOR EACH pt_mstr WHERE ( pt_mstr.pt_prod_line = "164" ),
    EACH ps_mstr NO-LOCK WHERE ps_par = pt_mstr.pt_part AND (ps_start = ? OR ps_start <= TODAY) AND (ps_end = ? OR ps_end >= TODAY) 
    BREAK BY ps_par BY ps_comp :

    IF FIRST-OF(ps_par) THEN
        state = "AC" .

    IF CAN-FIND(FIRST b_pt WHERE b_pt.pt_part = ps_comp AND b_pt.pt_status = "ST") THEN 
        state = "ST" .

    IF LAST-OF(ps_par) THEN DO:
        IF pt_mstr.pt_status = "AC" AND state = "ST" THEN
            pt_mstr.pt_status = state.
        ELSE IF pt_mstr.pt_status = "ST" AND state = "AC" THEN
            pt_mstr.pt_status = state.

    END.

END.

/*************************************************************************************************************************************/
FOR EACH pt_mstr WHERE ( pt_mstr.pt_prod_line = "163" ),
    EACH ps_mstr NO-LOCK WHERE ps_par = pt_mstr.pt_part AND (ps_start = ? OR ps_start <= TODAY) AND (ps_end = ? OR ps_end >= TODAY) 
    BREAK BY ps_par BY ps_comp :

    IF FIRST-OF(ps_par) THEN
        state = "AC" .

    IF CAN-FIND(FIRST b_pt WHERE b_pt.pt_part = ps_comp AND b_pt.pt_status = "ST") THEN 
        state = "ST" .

    IF LAST-OF(ps_par) THEN DO:
        IF pt_mstr.pt_status = "AC" AND state = "ST" THEN
            pt_mstr.pt_status = state.
        ELSE IF pt_mstr.pt_status = "ST" AND state = "AC" THEN
            pt_mstr.pt_status = state.

    END.

END.

/*************************************************************************************************************************************/
FOR EACH pt_mstr WHERE ( pt_mstr.pt_prod_line = "162" ),
    EACH ps_mstr NO-LOCK WHERE ps_par = pt_mstr.pt_part AND (ps_start = ? OR ps_start <= TODAY) AND (ps_end = ? OR ps_end >= TODAY) 
    BREAK BY ps_par BY ps_comp WITH FRAME a STREAM-IO :

    IF FIRST-OF(ps_par) THEN
        state = "AC" .

    IF CAN-FIND(FIRST b_pt WHERE b_pt.pt_part = ps_comp AND b_pt.pt_status = "ST") THEN 
        state = "ST" .

    IF LAST-OF(ps_par) THEN DO:
        IF pt_mstr.pt_status = "AC" AND state = "ST" THEN
            pt_mstr.pt_status = state.
        ELSE IF pt_mstr.pt_status = "ST" AND state = "AC" THEN
            pt_mstr.pt_status = state.

    END.

END.

/*************************************************************************************************************************************/
FOR EACH pt_mstr WHERE ( pt_mstr.pt_prod_line = "161" ),
    EACH ps_mstr NO-LOCK WHERE ps_par = pt_mstr.pt_part AND (ps_start = ? OR ps_start <= TODAY) AND (ps_end = ? OR ps_end >= TODAY) 
    BREAK BY ps_par BY ps_comp WITH FRAME a STREAM-IO :

    IF FIRST-OF(ps_par) THEN
        state = "AC" .

    IF CAN-FIND(FIRST b_pt WHERE b_pt.pt_part = ps_comp AND b_pt.pt_status = "ST") THEN 
        state = "ST" .

    IF LAST-OF(ps_par) THEN DO:
        IF pt_mstr.pt_status = "AC" AND state = "ST" THEN
            pt_mstr.pt_status = state.
        ELSE IF pt_mstr.pt_status = "ST" AND state = "AC" THEN
            pt_mstr.pt_status = state.
    END.

END.

/*************************************************************************************************************************************/
FOR EACH pt_mstr WHERE ( pt_mstr.pt_prod_line = "160" ),
    EACH ps_mstr NO-LOCK WHERE ps_par = pt_mstr.pt_part AND (ps_start = ? OR ps_start <= TODAY) AND (ps_end = ? OR ps_end >= TODAY) 
    BREAK BY ps_par BY ps_comp WITH FRAME a STREAM-IO :

    IF FIRST-OF(ps_par) THEN
        state = "AC" .

    IF CAN-FIND(FIRST b_pt WHERE b_pt.pt_part = ps_comp AND b_pt.pt_status = "ST") THEN 
        state = "ST" .

    IF LAST-OF(ps_par) THEN DO:
        IF pt_mstr.pt_status = "AC" AND state = "ST" THEN
            pt_mstr.pt_status = state.
        ELSE IF pt_mstr.pt_status = "ST" AND state = "AC" THEN
            pt_mstr.pt_status = state.
    END.

END.

/*************************************************************************************************************************************/
FOR EACH pt_mstr WHERE ( pt_mstr.pt_prod_line = "140" ),
    EACH ps_mstr NO-LOCK WHERE ps_par = pt_mstr.pt_part AND (ps_start = ? OR ps_start <= TODAY) AND (ps_end = ? OR ps_end >= TODAY) 
    BREAK BY ps_par BY ps_comp WITH FRAME a STREAM-IO :

    IF FIRST-OF(ps_par) THEN
        state = "AC" .

    IF CAN-FIND(FIRST b_pt WHERE b_pt.pt_part = ps_comp AND b_pt.pt_status = "ST") THEN 
        state = "ST" .

    IF LAST-OF(ps_par) THEN DO:
        IF pt_mstr.pt_status = "AC" AND state = "ST" THEN
            pt_mstr.pt_status = state.
        ELSE IF pt_mstr.pt_status = "ST" AND state = "AC" THEN
            pt_mstr.pt_status = state.
    END.

END.

/*************************************************************************************************************************************/
FOR EACH pt_mstr WHERE ( pt_mstr.pt_prod_line = "130" ),
    EACH ps_mstr NO-LOCK WHERE ps_par = pt_mstr.pt_part AND (ps_start = ? OR ps_start <= TODAY) AND (ps_end = ? OR ps_end >= TODAY) 
    BREAK BY ps_par BY ps_comp WITH FRAME a STREAM-IO :

    IF FIRST-OF(ps_par) THEN
        state = "AC" .

    IF CAN-FIND(FIRST b_pt WHERE b_pt.pt_part = ps_comp AND b_pt.pt_status = "ST") THEN 
        state = "ST" .

    IF LAST-OF(ps_par) THEN DO:
        IF pt_mstr.pt_status = "AC" AND state = "ST" THEN
            pt_mstr.pt_status = state.
        ELSE IF pt_mstr.pt_status = "ST" AND state = "AC" THEN
            pt_mstr.pt_status = state.
    END.

END.

/*************************************************************************************************************************************/
FOR EACH pt_mstr WHERE ( pt_mstr.pt_prod_line = "120" ),
    EACH ps_mstr NO-LOCK WHERE ps_par = pt_mstr.pt_part AND (ps_start = ? OR ps_start <= TODAY) AND (ps_end = ? OR ps_end >= TODAY) 
    BREAK BY ps_par BY ps_comp WITH FRAME a STREAM-IO :

    IF FIRST-OF(ps_par) THEN
        state = "AC" .

    IF CAN-FIND(FIRST b_pt WHERE b_pt.pt_part = ps_comp AND b_pt.pt_status = "ST") THEN 
        state = "ST" .

    IF LAST-OF(ps_par) THEN DO:
        IF pt_mstr.pt_status = "AC" AND state = "ST" THEN
            pt_mstr.pt_status = state.
        ELSE IF pt_mstr.pt_status = "ST" AND state = "AC" THEN
            pt_mstr.pt_status = state.
    END.

END.

/*************************************************************************************************************************************/
FOR EACH pt_mstr WHERE ( pt_mstr.pt_prod_line = "110" ),
    EACH ps_mstr NO-LOCK WHERE ps_par = pt_mstr.pt_part AND (ps_start = ? OR ps_start <= TODAY) AND (ps_end = ? OR ps_end >= TODAY) 
    BREAK BY ps_par BY ps_comp WITH FRAME a STREAM-IO :

    IF FIRST-OF(ps_par) THEN
        state = "AC" .

    IF CAN-FIND(FIRST b_pt WHERE b_pt.pt_part = ps_comp AND b_pt.pt_status = "ST") THEN 
        state = "ST" .

    IF LAST-OF(ps_par) THEN DO:
        IF pt_mstr.pt_status = "AC" AND state = "ST" THEN
            pt_mstr.pt_status = state.
        ELSE IF pt_mstr.pt_status = "ST" AND state = "AC" THEN
            pt_mstr.pt_status = state.
    END.

END.


/*************************************************************************************************************************************/

